package door.utils;

import app.nbdevices.utils.ConvertUtil;
import door.entity.DoorCmdData;
import door.entity.DoorCycleReport;
import door.modle.codecModle.DoorCmd;
import door.modle.codecModle.DoorReport;
import door.modle.revModle.RevDoorReportData;

import java.io.UnsupportedEncodingException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class DoorExplain {
public static DoorCycleReport exDoorReport(String deviceId,DoorReport doorReport){

    DoorCycleReport doorCycleReport=new DoorCycleReport();
    doorCycleReport.setDoorRssi(Byte.toUnsignedInt(doorReport.getRssi()));
    doorCycleReport.setDoorCheck(Integer.parseInt
            (ConvertUtil.byteToString(doorReport.getM_check())));
    doorCycleReport.setCityEle(Integer.parseInt
            (ConvertUtil.byteToString(doorReport.getC_ele())));
    doorCycleReport.setDoorEle(Integer.parseInt
            (ConvertUtil.byteToString(doorReport.getDev_ele())));
    doorCycleReport.setDoorVoltage((float)Byte.toUnsignedInt(doorReport.getVoltage())/10);
    doorCycleReport.setReportTime(LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")));
    String addrId=null;
    try {
        addrId=new String(doorReport.getAddressField(),"ascii");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    doorCycleReport.setAddrId(addrId);
    doorCycleReport.setInternetDeviceId(deviceId);
    return doorCycleReport;
}

    public static void main(String[] args) {
        String res="AABzDyA4UDYYERgBAAEoQAFTGGBV";
        String res1="AABzECA4UDYYERgBAAEoQAFTGGBV";
//        byte[] decode = ConvertUtil.getBase64Codec().decode(res);
//        byte[] decode1 = ConvertUtil.getBase64Codec().decode(res1);
//        RevDoorReportData revDoorReportData = new RevDoorReportData();
//        revDoorReportData.setReportData(res1);
//        revDoorReportData.setAddrId("VDAwMDYz");
//        RevDoorReportData revDoorReportDatas = new RevDoorReportData();
//        revDoorReportDatas.setReportData(res);
//        revDoorReportData.setAddrId("VDAwMDYz");
//        DoorReport doorReport = DoorDecode.doorReportDataDecode(revDoorReportData);
//        DoorReport doorReport1 = DoorDecode.doorReportDataDecode(revDoorReportDatas);
//        byte a=doorReport.getRssi();
//        byte b=doorReport1.getRssi();
//        System.out.println(a);
//        System.out.println(b);
//        System.out.println(ConvertUtil.byteToString(doorReport.getRssi()));
//        System.out.println();
//        for(byte b:decode){
//            System.out.print(Integer.toHexString(b&0xff)+" ");
//        }
//        System.out.println();
//        for(byte b:decode1){
//            System.out.print(Integer.toHexString(b&0xff)+" ");
//        }
//        RevDoorReportData revDoorReportData = new RevDoorReportData();
//        revDoorReportData.setReportData(res1);
//        revDoorReportData.setAddrId("VDAwMDYz");
//        DoorReport doorReport = DoorDecode.doorReportDataDecode(revDoorReportData);
//        DoorCycleReport doorCycleReport = exDoorReport("dddd",doorReport);
//        System.out.println(doorCycleReport);
    }
//public static DoorCmdData exDoorCmd(String deviceId, DoorCmd doorCmd){
//    DoorCmdData doorCmdData=new DoorCmdData();
//   // doorCmdData.s
//}
}
